#include <fastcommon/logger.h>
#include <fastdfs/fdfs_client.h>
#include <iostream>

int main()
{
    g_log_context.log_level = LOG_ERR;
    log_init();

    //2, 初始化客户端全局配置 (1, 从配置文件中初始化， 2， 从缓冲区进行初始化)
    int ret = fdfs_client_init("./client.conf");
    if(ret != 0)
    {
        std::cout << "fdfs_client_init failed, ret: " << STRERROR(ret) << std::endl;
        return -1;
    }

    //3,获得tracker服务器句柄
    auto tracker_server = tracker_get_connection();
    if(tracker_server == nullptr)
    {
        std::cout << "tracker_get_connection failed" << std::endl;
        return 1;
    }

    //4,文件上传
    char file_id[256];
    ret = storage_upload_by_filename1(tracker_server, nullptr, 0, "./upload.cc", nullptr, nullptr, 0, nullptr, file_id);
    if(ret != 0)
    {
        std::cout << "fdfs_upload_file failed, ret: " << STRERROR(ret) << std::endl;
        return 1;
    }

    std::cout << "文件上传成功" << file_id << std::endl;
    tracker_close_connection(tracker_server);
    fdfs_client_destroy();
    return 0;
}
